package org.com.real.version.module;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Logger;

import org.com.core.module.AbstractParser;
import org.htmlcleaner.CleanerProperties;
import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.PrettyHtmlSerializer;
import org.htmlcleaner.TagNode;

public class Connector extends AbstractParser {

	@Override
	public void LoadHtml(String filePath) throws IOException {
		CleanerProperties props = new CleanerProperties();
		TagNode tagNode = null;
		try	{
				props.setTranslateSpecialEntities(true);
				props.setTransResCharsToNCR(true);
				props.setOmitComments(true);
				tagNode = new HtmlCleaner(props).clean(new URL(filePath));
				new PrettyHtmlSerializer(props).writeToFile(tagNode,"default.html", "utf-8");
		} catch(IOException ex) {
			System.out.println("Page not found. Check your Internet connection and try again.");
			boolean success = (new File("default.html")).delete();
			if (success == false) {
				Logger.getLogger("The file was not successfully removed");
			}
			throw ex;

		}
	}
}
